package com.wwu.system.controller;

import com.wwu.common.constant.CommConst;
import com.wwu.common.enums.MenuBtnEnum;
import com.wwu.common.web.ResultObj;
import com.wwu.system.common.aspect.Log;
import com.wwu.system.entity.SysConfig;
import com.wwu.system.service.ISysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiSort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;

/**
 * 系统设置前端控制器
 * @author 一蓑烟雨
 * @date 2023/5/31 9:37
 */
@Api(tags = "系统设置控制器(SysConfigController)")
@ApiSort(3)
@Controller
@RequestMapping("/system/sysConfig")
public class SysConfigController {
    @Resource
    private ISysConfigService sysConfigService;

    /**
     * 请求转发到系统网站设置
     * @param model
     * @return java.lang.String
     * @author 一蓑烟雨
     * @date 2023/7/11 14:54
     */
    @GetMapping("/configMain")
    public String configMainHtml(Model model){
        model.addAttribute(CommConst.SYS_CONFIG,sysConfigService.getSysConfig());
        return "system/sysconfig/sys-config-info";
    }

    @Log(menuName = "网站配置",menuBtnEnum = MenuBtnEnum.UPDATE,saveRequestData = false)
    @ApiOperation(value = "更新网站配置图片")
    @ApiOperationSupport(order = 1)
    @PostMapping("/updateSysConfigImage")
    @ResponseBody
    public ResultObj updateSysConfigImage(String imageType, MultipartFile file){
        return sysConfigService.updateSysConfigImage(imageType,file);
    }

    @Log(menuName = "网站配置",menuBtnEnum = MenuBtnEnum.UPDATE)
    @ApiOperation(value = "更新系统配置信息")
    @ApiOperationSupport(order = 2)
    @PutMapping("/updateSysConfig")
    @ResponseBody
    public ResultObj updateSysConfig(@RequestBody SysConfig sysConfig){
        return sysConfigService.updateSysConfig(sysConfig);
    }
}